home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3044 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: colossus.holonet.net!russell
  2. From: russell@news.mdli.com (Russell Blackadar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: maddening constructor problem
  5. Date: 21 Jan 1996 21:52:13 GMT
  6. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  7. Message-ID: <4ducid$l3j@colossus.holonet.net>
  8. References: <4dr307$4so@noc2.drexel.edu>
  9. NNTP-Posting-Host: jubal.mdli.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Jonathan Juniman (st918h5w@dunx1.ocs.drexel.edu) wrote:
  13. : Maddening constructor problem:
  14.  
  15. : MYCLASS.H
  16. : class MyClass
  17. :     {
  18. :     public:
  19. :     MyClass(unsigned int i, insigned int j, double* pK);
  20. :     // etc
  21. :     }
  22.          ^ PUT A SEMICOLON HERE!!
  23.  
  24. : MYCLASS.CPP
  25. : MyClass::MyClass(unsigned int i, unsigned int j, double* pK)
  26. :     {
  27. :     // constructor code here
  28. :     }
  29.  
  30. : Visual C++ bites me on MYCLASS.CPP, saying "constructor not allowed
  31. : a return type".  What's the problem?  The constructor doesn't _have_
  32. : a return type. Please respond by e-mail.
  33.  
  34. I assume the first line of MYCLASS.CPP is #include "myclass.h" --
  35. if not, you should add this line.  Then, add the semicolon to your
  36. class definition and all should be fine.
  37.  
  38. Because of the missing semicolon, the function definition is part
  39. of the same statement as your class definition.  Syntactically, you
  40. are saying the function's return type is a MyClass object.
  41. --
  42. Russell Blackadar,   russell@mdli.com
  43.